package cn.kpi.service.pingyou.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import cn.kpi.dao.pingyou.PyResultDao;
import cn.kpi.entity.usualassessment.UserUATMzpdSummaryEntity;
import cn.kpi.service.pingyou.IPyResultService;

@Service
public class PyResultServiceImpl implements IPyResultService {
	
	@Autowired
	private PyResultDao pyResultDao;
	
	public int UpdateMzpdSummaryStatusById(Long mzpdsummaryid,int status)throws Exception{
		try{
			return pyResultDao.UpdateMzpdSummaryStatusById(mzpdsummaryid,status);
		}
		catch(Exception ex){
			ex.printStackTrace();
			return -1;
		}
	}
	
	 public List<UserUATMzpdSummaryEntity> GetMzpdSummaryListByWhere(String where,int year,String username)throws Exception{
		 try {
				return pyResultDao.GetMzpdSummaryListByWhere(where,year,username);
			} catch (Exception ex) {
				ex.printStackTrace();
				return null;
			}
	 }
	 public int GetMzpdSummaryListCountByWhere(String where,int year,String username)throws Exception{
		 try {
				return pyResultDao.GetMzpdSummaryListCountByWhere(where,year,username);
			} catch (Exception ex) {
				ex.printStackTrace();
				return -1;
			}
	 }
	 public List<Map> GetOrgPyResultTjList(String where,int year,int quarter)throws Exception{
		 try {
				return pyResultDao.GetOrgPyResultTjList(where,year,quarter);
			} catch (Exception ex) {
				ex.printStackTrace();
				return null;
			}
	 }

	@Override
	public List<Map> GetOldOrgPyResultTjList(String where, int year, int quarter) throws Exception {
		try {
			return pyResultDao.GetOldOrgPyResultTjList(where,year,quarter);
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}

	@Transactional
	public int UpdateOrgStatusGd(Long byuserid,Long orgstatustjid,String remark)throws Exception{
		 try {
				return pyResultDao.UpdateOrgStatusGd(byuserid,orgstatustjid,remark);
			} catch (Exception ex) {
				ex.printStackTrace();
				return -1;
			}
	 }

	@Override
	@Transactional
	public int backDataByStatusGd(int year, int quarter) throws Exception{
		try {
			int result=0;
			result+=pyResultDao.deleteUserorghz(year, quarter);
			result+=pyResultDao.insertUserorghz(year, quarter);
			return result;
		} catch (Exception ex) {
			ex.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return -1;
		}
	}


	 public int UpdateOrgStatusBh(Long byuserid,Long orgstatustjid,String remark,Long orgid,int year,int quarter)throws Exception{
		 try {
			 int result=0;
			 result+=pyResultDao.UpdateOrgStatusBh(byuserid, orgstatustjid, remark);
			 result+=pyResultDao.UpdateMzpdStatusForBh(orgid, year, quarter);
			 result+=pyResultDao.UpdateUserNodeMzpdForBh(orgid, year, quarter);
		     return result;
			} catch (Exception ex) {
				ex.printStackTrace();
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
				return -1;
			}
	 }
}
